# This file is part of Clipbox.
#
# Clipbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clipbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clipbox.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os

LEVELS={
    'QUIET': 0,
    'NONE': 0,
    'ERROR': 1,
    'WARNING': 2,
    'INFO': 3,
    'DEBUG': 4
}

if 'LOGGING' in os.environ and os.environ['LOGGING'] in LEVELS.keys():
    LOGGING=LEVELS[os.environ['LOGGING']]
else:
    LOGGING=LEVELS['DEBUG']

def log(s, level = LEVELS['INFO']):
    if level <= LOGGING:
        level_name = list(k for k,v in LEVELS.items() if v == level)[0]
        sys.stderr.write('[{level:^10}] {message}\n'.format(level=level_name, message=s))

def e(s):
    log(s, LEVELS['ERROR'])

def w(s):
    log(s, LEVELS['WARNING'])

def i(s):
    log(s, LEVELS['INFO'])

def d(s):
    log(s, LEVELS['DEBUG'])

v = d
